package com.example.graduatetest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.graduatetest.bean.Account;
import com.example.graduatetest.databinding.ActivityMainBinding;
import com.example.graduatetest.view.model.TestViewModel;

public class MainActivity extends AppCompatActivity {
    private Account account;
    ActivityMainBinding binding;
    TestViewModel viewModel;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this,R.layout.activity_main);

        //LiveData
        viewModel= ViewModelProviders.of(this).get(TestViewModel.class);
        viewModel.init(getApplication());
        binding.setViewModel(viewModel);

        binding.setLifecycleOwner(this);

        //DataBinding
        account = new Account();
        account.setName("test");
        account.setLevel(100);
        binding.setAccount(account);
        binding.setActivity(this);
    }

    public void onClick(View view){
        //Toast.makeText(this,"点击啦", Toast.LENGTH_SHORT).show();
       int level = account.getLevel();
       account.setLevel(level+1);

       //通知视图变化
       //binding.setAccount(account);
    }
}
